package com.sdruixinggroup.mondayb2b.widget;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sdruixinggroup.mondayb2b.R;
import com.sdruixinggroup.mondayb2b.models.OrderInfor;
import com.sdruixinggroup.mondayb2b.ui.Activities.AppraiseActivity;
import com.sdruixinggroup.mondayb2b.ui.WebActivity;
import com.sdruixinggroup.mondayb2b.utils.DisplayUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by 00029935 on 2017/12/7.
 */

public class OrderInforGoodView extends AbCustomHeaderView {
    @BindView(R.id.iv_pic)
    ImageView ivPic;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_count)
    TextView tvCount;
    @BindView(R.id.rl_content_click)
    RelativeLayout rlContentClick;
    @BindView(R.id.tv_praise)
    TextView tvPraise;
    @BindView(R.id.ll_praise)
    LinearLayout llPraise;
    private int id;
    private int orderID;
    private int order_goods_id;

    public OrderInforGoodView(Context context) {
        super(context);
    }

    public OrderInforGoodView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public OrderInforGoodView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public int getInflateLayout() {
        return R.layout.order_detail_good_view;
    }

    @Override
    public void setUpView(View view) {

    }

    public void setData(OrderInfor.OrderBean.OrderGoodsBean orderGoodsBean, int ordID, int orderStatus) {
        Glide.with(getContext()).load(orderGoodsBean.getGoods_pic()).error(R.drawable.order_merchandiser).into(ivPic);
        tvName.setText(orderGoodsBean.getGoods_name());
        tvPrice.setText("￥" + DisplayUtil.double2String(orderGoodsBean.getPrice()));
        tvCount.setText("×" + String.valueOf(orderGoodsBean.getQuantity()));
        id = orderGoodsBean.getGoods_id();

//        if(orderGoodsBean.getCommented() == 0){
//            llPraise.setVisibility(VISIBLE);
//        }else {
        llPraise.setVisibility(GONE);
//        }


        orderID = ordID;
        order_goods_id = orderGoodsBean.getOrder_goods_id();
//        if(orderStatus == 5){
//           int count=orderGoodsBean.getCommented();
//           if(count == 0){
//               tvPraise.setVisibility(VISIBLE);
//           }else {
//               tvPraise.setVisibility(GONE);
//           }
//        }else {
//            tvPraise.setVisibility(GONE);
//        }
    }

    @OnClick(R.id.rl_content_click)
    public void onViewClicked() {
        String url = "productdetail?goods_id=" + id;
        //  toWebView(url);
    }


    private void toWebView(String param) {
        Intent intent = new Intent(getContext(), WebActivity.class);
        intent.putExtra(WebActivity.INTENT_EXTRA_BEGIN_URL, param);
        getContext().startActivity(intent);
    }


    @OnClick(R.id.tv_praise)
    public void onViewClickedTV() {
        Intent intent = new Intent(getContext(), AppraiseActivity.class);
        intent.putExtra("ID", orderID);
        intent.putExtra("order_goods_id", order_goods_id);
        getContext().startActivity(intent);
    }
}
